


--use PolePosition

-- // checksum failed custom error
--exec sp_addmessage @msgnum = 505050, @severity = 16, @msgtext = N'%s(%s) checksum compare failed', @replace = 'REPLACE', @lang = 'us_english'
--GO

-- // not found custom error
--exec sp_addmessage @msgnum = 505060, @severity = 16, @msgtext = N'%s(%s) does not exist', @replace = 'REPLACE', @lang = 'us_english'
--GO

-- // unit test custom error
--exec sp_addmessage @msgnum = 505070, @severity = 16, @msgtext = N'%s Test Failed. Expected< %s > Actual< %s > %s', @replace = 'REPLACE', @lang = 'us_english'
--GO



--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'v_tb_Vendor_InspVisit_XmissionStructures_Poles') and OBJECTPROPERTY(id, N'IsProcedure') = 0)
drop view v_tb_Vendor_InspVisit_XmissionStructures_Poles
GO
            
create view v_tb_Vendor_InspVisit_XmissionStructures_Poles as
	/* 	Initial Generated Date:  Saturday, May 09, 2009 
		Purpose: Selected record(s) from the table; this view is the source for all procedures' select statements
	*/
	
select
	 [Vendor_InspVisit_XMissionStructure_PoleId] as [Vendor_InspVisit_XMissionStructure_PoleId]
	,[Latitude] as [Latitude]
	,[Longitude] as [Longitude]
	,[Year] as [Year]
	,[LVisit] as [LVisit]
	,[Number] as [Number]
	,[AcquisitionDate] as [AcquisitionDate]
	,[TreatmentFk] as [TreatmentFk]
	,[ClassFK] as [ClassFK]
	,[SpecieFk] as [SpecieFk]
	,[TopTypeFk] as [TopTypeFk]
	,[Length] as [Length]
	,[InspectorFk] as [InspectorFk]
	,[CompanyFk] as [CompanyFk]
	,[MapFk] as [MapFk]
	,[Vendor_InspVisit_XMissionStructureFk] as [Vendor_InspVisit_XMissionStructureFk]
	,[Vendor_ProjectFK] as [Vendor_ProjectFK]
	,[Vendor_ContactFK] as [Vendor_ContactFK]
	,[SectionFk] as [SectionFk]
	,[Utility_Asset_XMissionStructures_PoleFk] as [Utility_Asset_XMissionStructures_PoleFk]
	,[GuardsQuantity] as [GuardsQuantity]
	,[Vendor_Visit_TypeFK] as [Vendor_Visit_TypeFK]
	,[LInspector] as [LInspector]
	-- customization may be required for FriendlyName
	,Left(CONVERT(varchar(255), [Vendor_InspVisit_XMissionStructure_PoleId]), 255) as [FriendlyName]
from
	tb_Vendor_InspVisit_XmissionStructures_Poles
GO





--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorInspVisitXmissionStructuresPole_Test') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorInspVisitXmissionStructuresPole_Test
GO


create proc up_VendorInspVisitXmissionStructuresPole_Test
	@Vendor_InspVisit_XMissionStructure_PoleId int
as
	/* 	Initial Generated Date:  Saturday, May 09, 2009 
		Purpose: Test if a record exists, using the primary key
	*/

SET NOCOUNT ON	
	
if exists(
	select [Vendor_InspVisit_XMissionStructure_PoleId] 
	from [tb_Vendor_InspVisit_XmissionStructures_Poles] source
	where [source].[Vendor_InspVisit_XMissionStructure_PoleId] = @Vendor_InspVisit_XMissionStructure_PoleId)
begin
	return(1)
end
else
begin
	return(0)
end
GO






--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorInspVisitXmissionStructuresPole_Select') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorInspVisitXmissionStructuresPole_Select
GO

create proc up_VendorInspVisitXmissionStructuresPole_Select
	 @Vendor_InspVisit_XMissionStructure_PoleId int = null 
	,@Latitude float = null 
	,@Longitude float = null 
	,@Year int = null 
	,@LVisit datetime = null 
	,@Number nvarchar(100) = null 
	,@AcquisitionDate datetime = null 
	,@TreatmentFk int = null 
	,@ClassFK int = null 
	,@SpecieFk int = null 
	,@TopTypeFk int = null 
	,@Length int = null 
	,@InspectorFk int = null 
	,@CompanyFk int = null 
	,@MapFk int = null 
	,@Vendor_InspVisit_XMissionStructureFk int = null 
	,@Vendor_ProjectFK int = null 
	,@Vendor_ContactFK int = null 
	,@SectionFk int = null 
	,@Utility_Asset_XMissionStructures_PoleFk int = null 
	,@GuardsQuantity int = null 
	,@Vendor_Visit_TypeFK int = null 
	,@LInspector nvarchar(100) = null 
as
	/* 	Initial Generated Date:  Saturday, May 09, 2009 
		Purpose: Selected record(s) based on the passed arguments; no arguments returns all
	*/

SET NOCOUNT ON	

declare @table table
	(
	 Vendor_InspVisit_XMissionStructure_PoleId int
	,Latitude float
	,Longitude float
	,Year int
	,LVisit datetime
	,Number nvarchar(100)
	,AcquisitionDate datetime
	,TreatmentFk int
	,ClassFK int
	,SpecieFk int
	,TopTypeFk int
	,Length int
	,InspectorFk int
	,CompanyFk int
	,MapFk int
	,Vendor_InspVisit_XMissionStructureFk int
	,Vendor_ProjectFK int
	,Vendor_ContactFK int
	,SectionFk int
	,Utility_Asset_XMissionStructures_PoleFk int
	,GuardsQuantity int
	,Vendor_Visit_TypeFK int
	,LInspector nvarchar(100)
	,[FriendlyName] varchar(255)
	)
	
insert @table
	(
	 [Vendor_InspVisit_XMissionStructure_PoleId]
	,[Latitude]
	,[Longitude]
	,[Year]
	,[LVisit]
	,[Number]
	,[AcquisitionDate]
	,[TreatmentFk]
	,[ClassFK]
	,[SpecieFk]
	,[TopTypeFk]
	,[Length]
	,[InspectorFk]
	,[CompanyFk]
	,[MapFk]
	,[Vendor_InspVisit_XMissionStructureFk]
	,[Vendor_ProjectFK]
	,[Vendor_ContactFK]
	,[SectionFk]
	,[Utility_Asset_XMissionStructures_PoleFk]
	,[GuardsQuantity]
	,[Vendor_Visit_TypeFK]
	,[LInspector]
	,[FriendlyName]
	)
select 
	 [Vendor_InspVisit_XMissionStructure_PoleId]
	,[Latitude]
	,[Longitude]
	,[Year]
	,[LVisit]
	,[Number]
	,[AcquisitionDate]
	,[TreatmentFk]
	,[ClassFK]
	,[SpecieFk]
	,[TopTypeFk]
	,[Length]
	,[InspectorFk]
	,[CompanyFk]
	,[MapFk]
	,[Vendor_InspVisit_XMissionStructureFk]
	,[Vendor_ProjectFK]
	,[Vendor_ContactFK]
	,[SectionFk]
	,[Utility_Asset_XMissionStructures_PoleFk]
	,[GuardsQuantity]
	,[Vendor_Visit_TypeFK]
	,[LInspector]
	,[FriendlyName]
from v_tb_Vendor_InspVisit_XmissionStructures_Poles
where
		IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_InspVisit_XMissionStructure_PoleId], -1) = Coalesce(@Vendor_InspVisit_XMissionStructure_PoleId, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_InspVisit_XMissionStructure_PoleId], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Latitude], -1) = Coalesce(@Latitude, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Latitude], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Longitude], -1) = Coalesce(@Longitude, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Longitude], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Year], -1) = Coalesce(@Year, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Year], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[LVisit], '1/1/1900 12:00AM') = Coalesce(@LVisit, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[LVisit], '1/1/1900 12:00AM')
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Number], '') = Coalesce(@Number, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Number], '')
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[AcquisitionDate], '1/1/1900 12:00AM') = Coalesce(@AcquisitionDate, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[AcquisitionDate], '1/1/1900 12:00AM')
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[TreatmentFk], -1) = Coalesce(@TreatmentFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[TreatmentFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[ClassFK], -1) = Coalesce(@ClassFK, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[ClassFK], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[SpecieFk], -1) = Coalesce(@SpecieFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[SpecieFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[TopTypeFk], -1) = Coalesce(@TopTypeFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[TopTypeFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Length], -1) = Coalesce(@Length, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Length], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[InspectorFk], -1) = Coalesce(@InspectorFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[InspectorFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[CompanyFk], -1) = Coalesce(@CompanyFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[CompanyFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[MapFk], -1) = Coalesce(@MapFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[MapFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_InspVisit_XMissionStructureFk], -1) = Coalesce(@Vendor_InspVisit_XMissionStructureFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_InspVisit_XMissionStructureFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_ProjectFK], -1) = Coalesce(@Vendor_ProjectFK, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_ProjectFK], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_ContactFK], -1) = Coalesce(@Vendor_ContactFK, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_ContactFK], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[SectionFk], -1) = Coalesce(@SectionFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[SectionFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Utility_Asset_XMissionStructures_PoleFk], -1) = Coalesce(@Utility_Asset_XMissionStructures_PoleFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Utility_Asset_XMissionStructures_PoleFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[GuardsQuantity], -1) = Coalesce(@GuardsQuantity, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[GuardsQuantity], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_Visit_TypeFK], -1) = Coalesce(@Vendor_Visit_TypeFK, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_Visit_TypeFK], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[LInspector], '') = Coalesce(@LInspector, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[LInspector], '')

-- primary select
select * from @table





	-- VendorInspVisitXmissionStructuresImageCollection select

select
	v_tb_Vendor_InspVisit_XmissionStructures_Images.* 
from 
	v_tb_Vendor_InspVisit_XmissionStructures_Images 
	JOIN @table x ON v_tb_Vendor_InspVisit_XmissionStructures_Images.Vendor_InspVisit_XMissionStructure_PoleFk = x.Vendor_InspVisit_XMissionStructure_PoleId
	




	-- VendorInspVisitXmissionStructuresResultCollection select

select
	v_tb_Vendor_InspVisit_XmissionStructures_Results.* 
from 
	v_tb_Vendor_InspVisit_XmissionStructures_Results 
	JOIN @table x ON v_tb_Vendor_InspVisit_XmissionStructures_Results.Vendor_InspVisit_XMissionStructure_PoleFk = x.Vendor_InspVisit_XMissionStructure_PoleId
	

	
GO 





--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorInspVisitXmissionStructuresPole_Select_Top1') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorInspVisitXmissionStructuresPole_Select_Top1
GO

create proc up_VendorInspVisitXmissionStructuresPole_Select_Top1
	 @Vendor_InspVisit_XMissionStructure_PoleId int = null 
	,@Latitude float = null 
	,@Longitude float = null 
	,@Year int = null 
	,@LVisit datetime = null 
	,@Number nvarchar(100) = null 
	,@AcquisitionDate datetime = null 
	,@TreatmentFk int = null 
	,@ClassFK int = null 
	,@SpecieFk int = null 
	,@TopTypeFk int = null 
	,@Length int = null 
	,@InspectorFk int = null 
	,@CompanyFk int = null 
	,@MapFk int = null 
	,@Vendor_InspVisit_XMissionStructureFk int = null 
	,@Vendor_ProjectFK int = null 
	,@Vendor_ContactFK int = null 
	,@SectionFk int = null 
	,@Utility_Asset_XMissionStructures_PoleFk int = null 
	,@GuardsQuantity int = null 
	,@Vendor_Visit_TypeFK int = null 
	,@LInspector nvarchar(100) = null 
as
	/* 	Initial Generated Date:  Saturday, May 09, 2009 
		Purpose: Selected record(s) based on the passed arguments; no arguments returns all
	*/

SET NOCOUNT ON	

declare @table table
	(
	  Vendor_InspVisit_XMissionStructure_PoleId int
	, Latitude float
	, Longitude float
	, Year int
	, LVisit datetime
	, Number nvarchar(100)
	, AcquisitionDate datetime
	, TreatmentFk int
	, ClassFK int
	, SpecieFk int
	, TopTypeFk int
	, Length int
	, InspectorFk int
	, CompanyFk int
	, MapFk int
	, Vendor_InspVisit_XMissionStructureFk int
	, Vendor_ProjectFK int
	, Vendor_ContactFK int
	, SectionFk int
	, Utility_Asset_XMissionStructures_PoleFk int
	, GuardsQuantity int
	, Vendor_Visit_TypeFK int
	, LInspector nvarchar(100)
	,[FriendlyName] varchar(255)
	)

insert @table
	(
	 [Vendor_InspVisit_XMissionStructure_PoleId]
	,[Latitude]
	,[Longitude]
	,[Year]
	,[LVisit]
	,[Number]
	,[AcquisitionDate]
	,[TreatmentFk]
	,[ClassFK]
	,[SpecieFk]
	,[TopTypeFk]
	,[Length]
	,[InspectorFk]
	,[CompanyFk]
	,[MapFk]
	,[Vendor_InspVisit_XMissionStructureFk]
	,[Vendor_ProjectFK]
	,[Vendor_ContactFK]
	,[SectionFk]
	,[Utility_Asset_XMissionStructures_PoleFk]
	,[GuardsQuantity]
	,[Vendor_Visit_TypeFK]
	,[LInspector]
	,[FriendlyName]
	)
select TOP 1
	 [Vendor_InspVisit_XMissionStructure_PoleId]
	,[Latitude]
	,[Longitude]
	,[Year]
	,[LVisit]
	,[Number]
	,[AcquisitionDate]
	,[TreatmentFk]
	,[ClassFK]
	,[SpecieFk]
	,[TopTypeFk]
	,[Length]
	,[InspectorFk]
	,[CompanyFk]
	,[MapFk]
	,[Vendor_InspVisit_XMissionStructureFk]
	,[Vendor_ProjectFK]
	,[Vendor_ContactFK]
	,[SectionFk]
	,[Utility_Asset_XMissionStructures_PoleFk]
	,[GuardsQuantity]
	,[Vendor_Visit_TypeFK]
	,[LInspector]
	,[FriendlyName]
from v_tb_Vendor_InspVisit_XmissionStructures_Poles
where
		IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_InspVisit_XMissionStructure_PoleId], -1) = Coalesce(@Vendor_InspVisit_XMissionStructure_PoleId, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_InspVisit_XMissionStructure_PoleId], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Latitude], -1) = Coalesce(@Latitude, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Latitude], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Longitude], -1) = Coalesce(@Longitude, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Longitude], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Year], -1) = Coalesce(@Year, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Year], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[LVisit], '1/1/1900 12:00AM') = Coalesce(@LVisit, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[LVisit], '1/1/1900 12:00AM')
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Number], '') = Coalesce(@Number, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Number], '')
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[AcquisitionDate], '1/1/1900 12:00AM') = Coalesce(@AcquisitionDate, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[AcquisitionDate], '1/1/1900 12:00AM')
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[TreatmentFk], -1) = Coalesce(@TreatmentFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[TreatmentFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[ClassFK], -1) = Coalesce(@ClassFK, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[ClassFK], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[SpecieFk], -1) = Coalesce(@SpecieFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[SpecieFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[TopTypeFk], -1) = Coalesce(@TopTypeFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[TopTypeFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Length], -1) = Coalesce(@Length, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Length], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[InspectorFk], -1) = Coalesce(@InspectorFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[InspectorFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[CompanyFk], -1) = Coalesce(@CompanyFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[CompanyFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[MapFk], -1) = Coalesce(@MapFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[MapFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_InspVisit_XMissionStructureFk], -1) = Coalesce(@Vendor_InspVisit_XMissionStructureFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_InspVisit_XMissionStructureFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_ProjectFK], -1) = Coalesce(@Vendor_ProjectFK, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_ProjectFK], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_ContactFK], -1) = Coalesce(@Vendor_ContactFK, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_ContactFK], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[SectionFk], -1) = Coalesce(@SectionFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[SectionFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Utility_Asset_XMissionStructures_PoleFk], -1) = Coalesce(@Utility_Asset_XMissionStructures_PoleFk, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Utility_Asset_XMissionStructures_PoleFk], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[GuardsQuantity], -1) = Coalesce(@GuardsQuantity, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[GuardsQuantity], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_Visit_TypeFK], -1) = Coalesce(@Vendor_Visit_TypeFK, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[Vendor_Visit_TypeFK], -1)
	AND	IsNull([v_tb_Vendor_InspVisit_XmissionStructures_Poles].[LInspector], '') = Coalesce(@LInspector, [v_tb_Vendor_InspVisit_XmissionStructures_Poles].[LInspector], '')

-- primary select
select * from @table


	-- VendorInspVisitXmissionStructuresImageCollection select

select
	v_tb_Vendor_InspVisit_XmissionStructures_Images.* 
from 
	v_tb_Vendor_InspVisit_XmissionStructures_Images 
	JOIN @table x ON v_tb_Vendor_InspVisit_XmissionStructures_Images.Vendor_InspVisit_XMissionStructure_PoleFk = x.Vendor_InspVisit_XMissionStructure_PoleId
	

	-- VendorInspVisitXmissionStructuresResultCollection select

select
	v_tb_Vendor_InspVisit_XmissionStructures_Results.* 
from 
	v_tb_Vendor_InspVisit_XmissionStructures_Results 
	JOIN @table x ON v_tb_Vendor_InspVisit_XmissionStructures_Results.Vendor_InspVisit_XMissionStructure_PoleFk = x.Vendor_InspVisit_XMissionStructure_PoleId
	
	
	
GO 





--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorInspVisitXmissionStructuresPole_Insert') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorInspVisitXmissionStructuresPole_Insert
GO

create proc up_VendorInspVisitXmissionStructuresPole_Insert
	 @Vendor_InspVisit_XMissionStructure_PoleId int =null OUTPUT  
	,@Latitude float  
	,@Longitude float  
	,@Year int = null  
	,@LVisit datetime  
	,@Number nvarchar(100) = null  
	,@AcquisitionDate datetime  
	,@TreatmentFk int = null  
	,@ClassFK int = null  
	,@SpecieFk int = null  
	,@TopTypeFk int = null  
	,@Length int = null  
	,@InspectorFk int = null  
	,@CompanyFk int = null  
	,@MapFk int = null  
	,@Vendor_InspVisit_XMissionStructureFk int = null  
	,@Vendor_ProjectFK int = null  
	,@Vendor_ContactFK int = null  
	,@SectionFk int = null  
	,@Utility_Asset_XMissionStructures_PoleFk int = null  
	,@GuardsQuantity int = null  
	,@Vendor_Visit_TypeFK int = null  
	,@LInspector nvarchar(100) = null  
as
	/* 	Initial Generated Date:  Saturday, May 09, 2009 
		Purpose: Inserts a new record; missing arguments are set as their default (typically null)
	*/

SET NOCOUNT ON	
--int

insert tb_Vendor_InspVisit_XmissionStructures_Poles 
	(
	
	 [Latitude] 
	,[Longitude] 
	,[Year] 
	,[LVisit] 
	,[Number] 
	,[AcquisitionDate] 
	,[TreatmentFk] 
	,[ClassFK] 
	,[SpecieFk] 
	,[TopTypeFk] 
	,[Length] 
	,[InspectorFk] 
	,[CompanyFk] 
	,[MapFk] 
	,[Vendor_InspVisit_XMissionStructureFk] 
	,[Vendor_ProjectFK] 
	,[Vendor_ContactFK] 
	,[SectionFk] 
	,[Utility_Asset_XMissionStructures_PoleFk] 
	,[GuardsQuantity] 
	,[Vendor_Visit_TypeFK] 
	,[LInspector] 
	)
	values
	(
	
	 @Latitude 
	,@Longitude 
	,@Year 
	,@LVisit 
	,@Number 
	,@AcquisitionDate 
	,@TreatmentFk 
	,@ClassFK 
	,@SpecieFk 
	,@TopTypeFk 
	,@Length 
	,@InspectorFk 
	,@CompanyFk 
	,@MapFk 
	,@Vendor_InspVisit_XMissionStructureFk 
	,@Vendor_ProjectFK 
	,@Vendor_ContactFK 
	,@SectionFk 
	,@Utility_Asset_XMissionStructures_PoleFk 
	,@GuardsQuantity 
	,@Vendor_Visit_TypeFK 
	,@LInspector 
	)
set @Vendor_InspVisit_XMissionStructure_PoleId = scope_identity()
select * from v_tb_Vendor_InspVisit_XmissionStructures_Poles where Vendor_InspVisit_XMissionStructure_PoleId = @Vendor_InspVisit_XMissionStructure_PoleId

GO




--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorInspVisitXmissionStructuresPole_Update') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorInspVisitXmissionStructuresPole_Update
GO


create proc up_VendorInspVisitXmissionStructuresPole_Update
	 @Vendor_InspVisit_XMissionStructure_PoleId int  
	,@Latitude float = null  
	,@Longitude float = null  
	,@Year int = null  
	,@LVisit datetime = null  
	,@Number nvarchar(100) = null  
	,@AcquisitionDate datetime = null  
	,@TreatmentFk int = null  
	,@ClassFK int = null  
	,@SpecieFk int = null  
	,@TopTypeFk int = null  
	,@Length int = null  
	,@InspectorFk int = null  
	,@CompanyFk int = null  
	,@MapFk int = null  
	,@Vendor_InspVisit_XMissionStructureFk int = null  
	,@Vendor_ProjectFK int = null  
	,@Vendor_ContactFK int = null  
	,@SectionFk int = null  
	,@Utility_Asset_XMissionStructures_PoleFk int = null  
	,@GuardsQuantity int = null  
	,@Vendor_Visit_TypeFK int = null  
	,@LInspector nvarchar(100) = null  
	,@OriginalVendor_InspVisit_XMissionStructure_PoleId int  = null --Original PrimaryKey
	
as
	/* 	Initial Generated Date:  Saturday, May 09, 2009 
		Purpose: Updates an existing record, verifying exist; missing arguments persist original record value
		NOTE: this version of the update allows up to write nulls to the table.
	*/

SET NOCOUNT ON	

if @OriginalVendor_InspVisit_XMissionStructure_PoleId is null
	set @OriginalVendor_InspVisit_XMissionStructure_PoleId = @Vendor_InspVisit_XMissionStructure_PoleId

-- test
declare @Result bit
execute @Result = up_VendorInspVisitXmissionStructuresPole_Test @OriginalVendor_InspVisit_XMissionStructure_PoleId
if (not @Result = 1)
begin
	Declare @x varchar(100)
	Set @x = Convert(Varchar(100), @Vendor_InspVisit_XMissionStructure_PoleId)
	raiserror(505060, 16, 1, 'VendorInspVisitXmissionStructuresPole', @x)
	return
end

-- proceed
update tb_Vendor_InspVisit_XmissionStructures_Poles 
set

	 [Latitude] = IsNull(@Latitude, [source].[Latitude])
	,[Longitude] = IsNull(@Longitude, [source].[Longitude])
	,[Year] =  @Year
	,[LVisit] = IsNull(@LVisit, [source].[LVisit])
	,[Number] =  @Number
	,[AcquisitionDate] = IsNull(@AcquisitionDate, [source].[AcquisitionDate])
	,[TreatmentFk] =  @TreatmentFk
	,[ClassFK] =  @ClassFK
	,[SpecieFk] =  @SpecieFk
	,[TopTypeFk] =  @TopTypeFk
	,[Length] =  @Length
	,[InspectorFk] =  @InspectorFk
	,[CompanyFk] =  @CompanyFk
	,[MapFk] =  @MapFk
	,[Vendor_InspVisit_XMissionStructureFk] =  @Vendor_InspVisit_XMissionStructureFk
	,[Vendor_ProjectFK] =  @Vendor_ProjectFK
	,[Vendor_ContactFK] =  @Vendor_ContactFK
	,[SectionFk] =  @SectionFk
	,[Utility_Asset_XMissionStructures_PoleFk] =  @Utility_Asset_XMissionStructures_PoleFk
	,[GuardsQuantity] =  @GuardsQuantity
	,[Vendor_Visit_TypeFK] =  @Vendor_Visit_TypeFK
	,[LInspector] =  @LInspector
	
from tb_Vendor_InspVisit_XmissionStructures_Poles source
where
	[source].[Vendor_InspVisit_XMissionStructure_PoleId] = @OriginalVendor_InspVisit_XMissionStructure_PoleId


select * from v_tb_Vendor_InspVisit_XmissionStructures_Poles where Vendor_InspVisit_XMissionStructure_PoleId = @Vendor_InspVisit_XMissionStructure_PoleId
GO





--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorInspVisitXmissionStructuresPole_Delete') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorInspVisitXmissionStructuresPole_Delete
GO


create proc up_VendorInspVisitXmissionStructuresPole_Delete
	@Vendor_InspVisit_XMissionStructure_PoleId int
as
	/* 	Initial Generated Date:  Saturday, May 09, 2009 
		Purpose: Deletes an existing record, verifying exist
	*/

SET NOCOUNT ON	

-- test
declare @Result bit
execute @Result = up_VendorInspVisitXmissionStructuresPole_Test @Vendor_InspVisit_XMissionStructure_PoleId
if (not @Result = 1)
begin
	Declare @x varchar(100)
	Set @x = Convert(Varchar(100), @Vendor_InspVisit_XMissionStructure_PoleId)
	raiserror(505060, 16, 1, 'VendorInspVisitXmissionStructuresPole', @x)
	return
end

-- proceed
delete from tb_Vendor_InspVisit_XmissionStructures_Poles 
where [Vendor_InspVisit_XMissionStructure_PoleId] = @Vendor_InspVisit_XMissionStructure_PoleId

GO


